package com.leenmvc.core.security.entity.core;

import com.leenmvc.core.annotation.DbInfo;
import com.leenmvc.core.annotation.FillField;
import com.leenmvc.core.annotation.PrimaryKey;
import com.leenmvc.core.annotation.TableField;
import com.leenmvc.core.annotation.validator.Foreign;
import com.leenmvc.core.annotation.validator.Uniqueness;
import com.leenmvc.core.annotation.validator.groups.AddGroup;
import com.leenmvc.core.annotation.validator.groups.UpdateGroup;
import com.leenmvc.core.base.BaseEntity;
import com.leenmvc.core.security.dao.core.SysPermissionDao;
import com.leenmvc.core.security.dao.core.SysRoleDao;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 角色权限列表
 *
 */
@DbInfo(value = "sys_role_permission", comment = "角色权限")
public class SysRolePermission extends BaseEntity implements Serializable {

    @PrimaryKey
    private Long id;

    @Foreign(message = "角色不存在！", value = SysRoleDao.class, groups = {AddGroup.class, UpdateGroup.class})
    @NotNull(message = "角色不能为空！", groups = {AddGroup.class, UpdateGroup.class})
    @Uniqueness(linkFields = {"permissionId"}, groups = {AddGroup.class, UpdateGroup.class})
    private Long roleId;

    @TableField(false)
    @FillField(entity = SysRole.class, outField = "name", inField = "roleId")
    private String roleName;

    @Foreign(message = "不存在这个权限记录", value = SysPermissionDao.class, groups = {AddGroup.class, UpdateGroup.class})
//    @NotNull(message = "权限不能为空！", groups = {AddGroup.class, UpdateGroup.class})
    private Long permissionId;

    @TableField(false)
    @FillField(entity = SysPermission.class, outField = "name", inField = "permissionId")
    private String permissionName;

    @TableField(false)
    @NotNull(message = "权限列表不能为空！", groups = {AddGroup.class, UpdateGroup.class})
    private Long[] permissionList;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public Long getPermissionId() {
        return permissionId;
    }

    public void setPermissionId(Long permissionId) {
        this.permissionId = permissionId;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }

    public Long[] getPermissionList() {
        return permissionList;
    }

    public void setPermissionList(Long[] permissionList) {
        this.permissionList = permissionList;
    }
}
